package com.hmall.search.Controller;

import com.hmall.common.VO.FiterVO;
import com.hmall.common.dto.FiltDTO;
import com.hmall.common.dto.PageDTO;
import com.hmall.item.pojo.PageResult;
import com.hmall.search.Service.SearchService;
import com.hmall.search.pojo.ItemDoc;
import com.hmall.search.pojo.RequestParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/search")
public class SearchController {
    @Autowired
    private SearchService searchService;

    /**
     * @Auth: wangxinglong
     * @desc:自动补全请求
     * @Date: 2023/6/28 10:53
     */
    @GetMapping("/suggestion")
    public List<String> getSuggestions(@RequestParam("key") String prefix) throws IOException {
        return searchService.getSuggestions(prefix);
    }

    /**
     * @Auth: wangxinglong
     * @desc:过滤项聚合
     * @Date: 2023/6/28 10:59
     */
    @PostMapping("/filters")
    public Map<String, List<String>> getFilters(@RequestBody RequestParams requestParam) {
        return searchService.getFilters(requestParam);
    }

    /**
     * @Auth: wangxinglong
     * @desc:分页查询
     * @Date: 2023/7/1 9:58
     */
    @PostMapping("/list")
    public PageResult page(@RequestBody FiltDTO filtDTO) {
        PageResult pageResult = searchService.page(filtDTO);
        return pageResult;
    }
}
